//
//  YYJLVideoDetailController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/10.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLVideoDetailController.h"
#import "YYJLVideoCommentController.h"
#import "YYJLVideoInformationController.h"
#import "YYJLTestController.h"
@interface YYJLVideoDetailController ()
{
    UIView     * playview;//播放视频区域
    UIImageView* showPic;//展示图片
    UIButton   * playBtnB;//播放按钮(大)
    UIButton   * playBtnS;//播放按钮(小)
    UILabel    * currentLb;//当前播放时间
    UILabel    * totalLb;//总时间
    UISlider   *  progressSlider;//滑块
    UIView     * line1;
    UIView     * line2;
    UIScrollView * _scrollview;
    UIButton   * evaluteBtn;
    UIButton   * summaryBtn;
}
@end

@implementation YYJLVideoDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleView:@"视频详情"];
    [self setBackItem];
    [self addHeaderView];
    [self addChangeBtn];
    [self creatBottomView];
    [self addBottomBtn];
}
//头部播放
-(void)addHeaderView{
    playview =[[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 250*PER_HEIGHT)];
    [self.view addSubview:playview];
    
    showPic=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250*PER_HEIGHT)];
    showPic.image=[UIImage imageNamed:@"img_gonggao2"];
    [playview addSubview:showPic];
    
    UIImage * playImg1=[UIImage imageNamed:@"ico_bofang_xiangqing"];
    playBtnB=[MyControl createButtonWithFrame:CGRectMake(157*PER_WIDTH, 72*PER_HEIGHT, playImg1.size.width*PER_WIDTH, playImg1.size.width*PER_WIDTH) ImageName:@"ico_bofang_xiangqing" Target:self Action:@selector(playBtnB) Title:@""];
    [playview addSubview:playBtnB];
    //透色view
    UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0, playview.height-44*PER_HEIGHT, SCREEN_WIDTH, 44*PER_HEIGHT)];
    view.backgroundColor=[UIColorFromHex(0x000000)colorWithAlphaComponent:.5];
    [playview addSubview:view];
    
    UIImage * playImg2=[UIImage imageNamed:@"ico_bofang1"];
    playBtnS=[MyControl createButtonWithFrame:CGRectMake(10*PER_WIDTH, 12*PER_HEIGHT, playImg2.size.width*PER_WIDTH, playImg2.size.height*PER_WIDTH) ImageName:@"ico_bofang1" Target:self Action:@selector(playBtnS) Title:@""];
    [view addSubview:playBtnS];
    
    currentLb=[MyControl createLabelWithFrame:CGRectMake(playBtnS.right+10*PER_WIDTH, 15*PER_HEIGHT, 40*PER_WIDTH, 14*PER_HEIGHT) Font:14 Text:@"00:00" Color:WHITE_COLOR];
    currentLb.font=[UIFont fontWithName:HLT  size:14];
    [view addSubview:currentLb];
    
    progressSlider=[[UISlider alloc]initWithFrame:CGRectMake(currentLb.right+7*PER_WIDTH, 20*PER_HEIGHT, 200*PER_WIDTH, 4*PER_HEIGHT)];
    [progressSlider addTarget:self action:@selector(progressChange:) forControlEvents:UIControlEventValueChanged];
    progressSlider.minimumValue = 0;
    progressSlider.maximumValue = 1;
    progressSlider.value = 0;
    progressSlider.minimumTrackTintColor = UIColorFromHex(0xdea556);
    progressSlider.maximumTrackTintColor = WHITE_COLOR;
    //[progressSlider setThumbImage:[UIImage imageNamed:@"lunbo1"] forState:UIControlStateNormal];
    [view addSubview:progressSlider];
    
    totalLb=[MyControl createLabelWithFrame:CGRectMake(progressSlider.right+7*PER_WIDTH, currentLb.top, currentLb.width, currentLb.height) Font:14 Text:@"00:00" Color:WHITE_COLOR];
    totalLb.font=[UIFont fontWithName:HLT size:14];
    [view addSubview:totalLb];
    
    UIImage * img=[UIImage imageNamed:@"ico_quanping"];
    UIButton * screenBtn =[MyControl createButtonWithFrame:CGRectMake(view.width-20*PER_WIDTH-img.size.width*PER_WIDTH, 13*PER_HEIGHT, img.size.width*PER_WIDTH, img.size.width*PER_WIDTH) ImageName:@"ico_quanping" Target:self Action:@selector(screen) Title:@""];
    [view addSubview:screenBtn];
    
}

#pragma mark--头部点击时间
-(void)playBtnB{
    //大按钮点击
}
-(void)playBtnS{
    //小按钮点击
}
-(void)progressChange:(UISlider*)slider{
    //进度条滑动
}
-(void)screen{
    //全屏
}
#pragma mark--中间按钮切换
-(void)addChangeBtn{
    UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0, playview.bottom, SCREEN_WIDTH, 44*PER_HEIGHT)];
    [self.view addSubview:view];
    
    UIView * line =[[UIView alloc]initWithFrame:CGRectMake(0, view.height-0.5, view.width, 0.5)];
    line.backgroundColor=UIColorFromHex(0xcccccc);
    [view addSubview:line];
    
    summaryBtn =[MyControl createButtonWithFrame:CGRectMake(0, 0, view.width/2, view.height-0.5) ImageName:@"" Target:self Action:@selector(summaryBtn:) Title:@"简介"];
    [summaryBtn setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
    [summaryBtn setTitleColor:TINK_COLOR forState:UIControlStateSelected];
    summaryBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    summaryBtn.selected=YES;
    [view addSubview:summaryBtn];
    line1=[[UIView alloc]initWithFrame:CGRectMake(summaryBtn.width/2-SCREEN_WIDTH/10, 42*PER_HEIGHT, SCREEN_WIDTH/5, 2*PER_HEIGHT)];
    line1.backgroundColor=TINK_COLOR;
    [summaryBtn addSubview:line1];
    
    
    evaluteBtn=[MyControl createButtonWithFrame:CGRectMake(summaryBtn.right, 0, view.width/2, summaryBtn.height) ImageName:@"" Target:self Action:@selector(evaluteBtn:) Title:@"评价(2)"];
    [evaluteBtn setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
    [evaluteBtn setTitleColor:TINK_COLOR forState:UIControlStateSelected];
    evaluteBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [view addSubview:evaluteBtn];
    line2=[[UIView alloc]initWithFrame:CGRectMake(summaryBtn.width/2-SCREEN_WIDTH/10, 42*PER_HEIGHT, SCREEN_WIDTH/5, 2*PER_HEIGHT)];
    line2.backgroundColor=TINK_COLOR;
    [evaluteBtn addSubview:line2];
    line2.hidden=YES;

    
    
}
-(void)summaryBtn:(UIButton*)sender{
    sender.selected=!sender.selected;
    evaluteBtn.selected=!sender.selected;
    line1.hidden=NO;
    line2.hidden=YES;
    _scrollview.contentSize=CGSizeMake(0, 530*PER_HEIGHT-64);
    [self remove];
    [self addController];
    
}
-(void)remove{
    if (self.childViewControllers.count==0) {
        return;
    }
    for (id view  in _scrollview.subviews) {
        [view removeFromSuperview];
    }

    for (id controler in self.childViewControllers) {
        [controler removeFromParentViewController];
    }
}
-(void)evaluteBtn:(UIButton*)sender{
     sender.selected=!sender.selected;
    summaryBtn.selected=!sender.selected;
    line1.hidden=YES;
    line2.hidden=NO;
    
    [self remove];
    YYJLVideoCommentController* comment =[[YYJLVideoCommentController alloc]init];
    [self addChildViewController:comment];
    comment.view.frame=CGRectMake(_scrollview.width, 0, _scrollview.width, _scrollview.height);
    _scrollview.contentSize=CGSizeMake(0, 0);
    comment.view.frame = _scrollview.bounds;
    [_scrollview addSubview:comment.view];
}
#pragma mark--子视图区域
-(void)creatBottomView{
    _scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, playview.bottom+44*PER_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-105*PER_HEIGHT-playview.height-64)];
    _scrollview.backgroundColor=[UIColor cyanColor];
    [self.view addSubview:_scrollview];
    [self addController];
    
}
-(void)addController{
   
    
    YYJLVideoInformationController * information =[[YYJLVideoInformationController alloc]init];
    [self addChildViewController:information];
    information.view.frame=CGRectMake(0, 0, _scrollview.width, _scrollview.height);
     [_scrollview addSubview:information.view];
  
      _scrollview.contentSize=CGSizeMake(0, 530*PER_HEIGHT-64);
  
   
}
#pragma mark--底部按钮
-(void)addBottomBtn{
    UIButton * bottomBtn=[MyControl createButtonWithFrame:CGRectMake(126*PER_WIDTH, SCREEN_HEIGHT-56*PER_HEIGHT, 120*PER_WIDTH, 36*PER_HEIGHT) ImageName:@"" Target:self Action:@selector(test) Title:@"课后小测"];
    bottomBtn .layer.cornerRadius=bottomBtn.height/2;
    bottomBtn.titleLabel.font=[UIFont systemFontOfSize:16*PER_WIDTH];
    [bottomBtn setTitleColor:WHITE_COLOR forState:0];
    bottomBtn.backgroundColor=TINK_COLOR;
    [self.view addSubview:bottomBtn];
}
-(void)test{
    YYJLTestController * test=[[YYJLTestController alloc]init];
    test.testType=AfterTest;
    [self.navigationController pushViewController:test animated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
